package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.SysJobTimeQueryDTO;
import com.cddx.logistics.domain.pojo.SysJobtime;
import com.cddx.logistics.domain.vo.SysJobTimeVO;
import com.cddx.logistics.service.SysJobtimeService;
import com.cddx.logistics.util.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sysjobtime")
@Api(tags = "定时任务管理器")
public class SysJobtimeController {
    @Autowired
    private SysJobtimeService sysJobtimeService;


    @GetMapping("/queryPage")
    @ApiModelProperty("分页查询定时任务")
    public R    queryPage(SysJobTimeQueryDTO sysJobTimeQueryDTO) {
        PageInfo<SysJobTimeVO> pageInfo = sysJobtimeService.queryPage(sysJobTimeQueryDTO);
        return R.ok(pageInfo);
    }

    @PostMapping("/add")
    @ApiModelProperty("添加定时任务")
    public R    add(SysJobtime sysJobtime){
        return sysJobtimeService.add(sysJobtime)?R.ok("添加成功"):R.error("添加失败");
    }

    @PostMapping("/update")
    @ApiModelProperty("修改定时任务")
    public R    update(SysJobtime sysJobtime) {
        return sysJobtimeService.update(sysJobtime)?R.ok("修改成功"):R.error("修改失败");
    }

    @GetMapping("/delete")
    @ApiModelProperty("删除定时任务")
    public R    deleteJob(Integer id) {
        return sysJobtimeService.delete(id)?R.ok("删除成功"):R.error("删除失败");
    }

    /**
     * 更新任务状态（启动/停用）
     */
    @PostMapping("/updateStatus")
    @ApiModelProperty("更新任务状态")
    public R    updateStatus(Integer id, Integer jobStatus) {
        SysJobtime sysJobtime = new SysJobtime();
        sysJobtime.setId(id);
        sysJobtime.setJobStatus(jobStatus);
        return sysJobtimeService.updateStatus(id,jobStatus) ? R.ok("状态更新成功") : R.error("状态更新失败");
    }

}
